home *** CD-ROM | disk | FTP | other *** search
- Path: Rezonet.net!news
- From: ray@ultimate-tech.com (Ray Dunn)
- Newsgroups: comp.lang.c
- Subject: Re: Recursive function -> how do you exit one?
- Date: 2 Feb 1996 18:38:32 GMT
- Organization: Ultimate Technographics Inc.
- Message-ID: <4etln8$63d@ns.RezoNet.NET>
- References: <4eh1g8$aba@pulp.ucs.ualberta.ca> <310d27a6.171790522@news.demon.co.uk> <4elvt9$ood@news.bellglobal.com>
- NNTP-Posting-Host: 204.19.230.7
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In referenced article, Steve Tupy says...
- >: You need to return a value which makes all the recursed functions
- >: exit without further processing.
- >
- >: if the function returns an int then you could return -1 as aborted.
- >: if it returns a char or char* you can use a (first) character that
- >: cannot exist in your string. eg 0xff
- >
- >: char* foo()
- >: {
- >: result=foo();
- >: if(*result!=0xff)
- >: {
- >: // process things here //
- >: if (aborted) return "\xff";
- >: }
- >: return result;
- >: }
- >
- >: Does that help?
- >
- > What is result, an int? Where is it defined? Don't you agree
- >that it should also be static? If not, you might find that its value
- >gets lost on the stack, especially when you are unwinding the stack
- >during a recursive call...
-
- The declaration of result has certainly been ommitted here, and because
- it is getting the result of foo(), it should be a char *; A more
- natural thing to return in the aborted state would be NULL.
-
- But in any case, there is absolutely no need for result to be static,
- as on every return, result is being reupdated with the current result
- of foo.
-
- --
- Ray Dunn (opinions are my own) | Phone: (514) 938 9050
- Montreal | Phax : (514) 938 5225
- ray@ultimate-tech.com | Home : (514) 630 3749
-
-